import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Puertas here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Puertas extends Actor
{
    /**
     * Act - do whatever the Puertas wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private int n=6;
    public void act() 
    {
        // Add your action code here.
        interseccionPuertas();
    } 
    /**
     * Metodo que se encarga de revisar si hay interseccion con las 2 puertas
     */
    public void interseccionPuertas()
    {
     Actor rojo= getOneIntersectingObject(sonicRojo.class);
     Actor azul= getOneIntersectingObject(sonicAzul.class);
     
     Mundo w=(Mundo) super.getWorld();
   //  System.out.println("Puerta Encontrada por azul");
     if((rojo!=null && azul!=null)){
      w.eliminaObjetos();
      if(w.Nivel==1){
      w.V2=w.V;
      w.V2R=w.VR;
      }else
      if(w.Nivel==2){
          w.V3=w.V2;
          w.V3R=w.V2R; 
        }
        
      if(w.Nivel==3){
      w.prepare(10);w.V=9;w.VR=9;w.dineroAzul=0;w.dineroRojo=0;}
      else
       w.prepare(w.Nivel+1);
  
     
      }
   }
}
